<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ include file="/common/taglibs.jsp"%>
<x:parse xml="${param.xmlstr}" var="xmlData" />
<div class="t_bar">
	<span class="color_red">*</span>研究进度和阶段目标
</div>
	<table  id="tblMileStones" cellpadding="0" class="table01" width="100%" border="0" cellpadding="0">
			<thead>
					<tr>
						<th class="TblHead" align="center" width="60px">选择</th>
						<th class="TblHead" align="center" width="60px">序号</th>
						<th class="TblHead" align="center" width="160px">开始日期</th>
						<th class="TblHead" align="center" width="160px">结束日期</th>
						<th class="TblHead" align="center"  >主要工作内容和阶段目标(限500字)</th> 
					</tr>
			</thead>
			<tbody id="tab">
					<tr style="display:none">
						<td>&nbsp;
							<input type="radio" class="radiobutton" name="selMileStones" >
						</td>
						<td>&nbsp;
							<span name="milestones|milestone[0]@seq_no" >[index]</span> 
						</td>
						<td>&nbsp;
							<cpt:date id="milestone_start_date_[0]" name="proposal/end_date" 
							className="required input_text date afterToday dateCompare:end_date" 
							label="开始日期"  
							value="" 
							onChange="changeDate('ww')" >
							</cpt:date> 
							
						</td>
						<td>&nbsp;
						    <cpt:date id="milestone_end_date_[0]" name="milestones|milestone[0]|end_date" 
							className="required input_text date afterToday dateCompare:end_date" 
							label="结束日期"  
							value="" 
							onChange="changeDate(this.id)" >
							</cpt:date> 
						</td> 
						<td>&nbsp;<textarea name="milestones|milestone[0]|content" class="input_textarea required" label="主要工作内容" onfocus="InitInput.setMaxLength(this,500)"  rows=2 cols=58></textarea></td> 
					</tr>
					<c:set value="0" var="index" scope="page"/>
					<x:forEach select="$xmlData/data/milestones/milestone" var="milestone">
					
					<c:choose>
						<c:when test="${index<10}" >
						<c:set value="0" var="flag" scope="page"/>
						</c:when>
						<c:otherwise>
						<c:set value="" var="flag" scope="page"/>
						</c:otherwise>
					</c:choose>
					<tr >
						<td>&nbsp;
							<input type="radio" class="radiobutton" name="selMileStones" >
						</td>
						<td>
							<span name="milestones/milestone[${flag}${index}]@seq_no" ><x:out select="$milestone/@seq_no"/></span> 
						</td>
						<td>&nbsp;
							<c:set var="start_date" scope="page"><x:out select="$milestone/start_date"/></c:set>
							<cpt:date id="milestone_start_date_[${flag}${index}]" name="milestones/milestone[${flag}${index}]/start_date" 
							className="required input_text date afterToday dateCompare:end_date" 
							label="开始日期"  
							value="${start_date}" 
							onChange="changeDate(this.id)" >
							</cpt:date> 
						</td>
						<td>&nbsp;
							<c:set var="end_date" scope="page"><x:out select="$milestone/end_date"/></c:set>
							<cpt:date id="milestone_end_date_[${flag}${index}]" name="milestones/milestone[${flag}${index}]/end_date" 
							className="required input_text date afterToday dateCompare:end_date" 
							label="结束日期"  
							value="${end_date}" 
							onChange="changeDate(this.id)" >
							</cpt:date> 
						</td> 
						<td>&nbsp;
							<textarea name="milestones/milestone[${flag}${index}]/content" class="input_textarea required" label="主要工作内容" onfocus="InitInput.setMaxLength(this,500)"rows=4 cols=58><x:out select="$milestone/content"/></textarea>
						</td>
					</tr>
					<c:set value="${index+1}" var="index" scope="page"/>
					</x:forEach>
					<script type="text/javascript">
						showAllDateTag("tblMileStones");
					</script>
				</tbody>
					</table>
					<br>

					<table width="98%" align="center">
					<tr ><td>
					<input class="button" name="cmdAddbefore" type=button value="追加一行" onclick="validateByTabAddRow('tblMileStones','研究进度和阶段目标');">
					<!-- 
					<input class="button" name="cmdMovePrev" type=button value="上移" onclick="movePrev('tblMileStones','selMileStones')">
					<input class="button" name="cmdMoveNext" type=button value="下移" onclick="moveNext('tblMileStones','selMileStones')">
					-->
					<input class="button" name="cmddel" type=button  value="删除最后一行" onclick="deleteSelectedRow('tblMileStones','进度')">
					</td></tr>
	</table>

	
	
<script type="text/javascript">
function validateByTabAddRow(tableid,title){
	var flag=true;
	$("#"+tableid).find("tr").each(function(index){
		if(index>=2){
			rtitle=messageTip.rowIndex.replace("[name]",title).replace("[index]",index-1);
			validate($(this),rtitle);
			if(!valResult()){
				irisValShowMsg($("#wbox1"));
				flag=false;
			}
			
		}
	});
	if(flag){
		addNewRow(tableid);
		showDateTag(tableid);
		try{
			top.resizeFrame();
		}
		catch(e){};
	}
	
	var nRowCnt=$("#"+tableid+" tr").length-2;	
	if(nRowCnt>1){
		var upRow = nRowCnt - 1;
		if(upRow<10){
		    upRow = "0"+upRow;
		}
		nRowCnt = nRowCnt - 2;
		if(nRowCnt<10)	{
			nRowCnt = "0"+nRowCnt;
		}
		var currentDate = $("#milestone_end_date_\\["+nRowCnt+"\\]").val();
		//$("#proposal\\/start_date1").val($("#"+"milestone_end_date_//[00//]").val());
		//$("#proposal\\/end_date1").val(currentDate);
		var outputdate= addOneDay(currentDate);
		$("#milestone_start_date_\\["+upRow+"\\]").val(outputdate);
		$("#milestone_start_date_\\["+upRow+"\\]").attr("disabled","disabled");
		$("#milestone_start_date_\\["+upRow+"\\]").parent().children("img").css('display','none');
		$("#milestone_start_date_\\["+upRow+"\\]").addClass("gray");
	}
}

function changeDate(id){
     alert("dd");
}

function addOneDay(startDate) {
	var y = parseInt(startDate.substring(0,4), 10);
	var m = parseInt(startDate.substring(5,7), 10);
	var d = parseInt(startDate.substring(8), 10);
	if(m==12&&d==31) {//一年最后一天
		y = y + 1;
		m = 1;
		d = 1;
	} else if(m==2&&d==29&&((y%4==0&&y%100!=0)||y%400==0||(y%3200==0&&y%172800==0))){//闰年的2月最后一天
		m = 3;
		d = 1;
	} else if((m==2&&d==28 && !((y%4==0&&y%100!=0)||y%400==0||(y%3200==0&&y%172800==0)))||((m==1||m==3||m==5||m==7||m==8||m==10||m==12)&&d==31)||((m==4||m==6||m==9||m==11)&&d==30)) {	//一个月的最后一天
		m = m + 1;
		d = 1;
	} else {	//其他日期
		d = d + 1;
	}
	if(m < 10)
		m = "0" + m;
	if(d < 10)
		d = "0" + d;
	return y + "-" + m + "-" + d;
}
</script>